﻿using QuickManager.Code;
using QuickManager.Code.Config;
using QuickManager.Code.Config.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QuickManager.UI.Config
{
    public partial class MainConfig : Form
    {
        public MainConfig()
        {
            InitializeComponent();
        }

        private void MainConfig_Load(object sender, EventArgs e)
        {
            ConfigModel configVS2005 = ConfigManager.GetConfig(VSVersion.VS2005.ToString())
                ?? new ConfigModel()
                {
                    ConfigValue = string.Empty
                };
            ConfigModel configVS2008 = ConfigManager.GetConfig(VSVersion.VS2008.ToString())
                ?? new ConfigModel()
                {
                    ConfigValue = string.Empty
                };
            ConfigModel configVS2010 = ConfigManager.GetConfig(VSVersion.VS2010.ToString())
                ?? new ConfigModel()
                {
                    ConfigValue = string.Empty
                };
            ConfigModel configVS2012 = ConfigManager.GetConfig(VSVersion.VS2012.ToString())
                ?? new ConfigModel()
                {
                    ConfigValue = string.Empty
                };
            ConfigModel configVS2013 = ConfigManager.GetConfig(VSVersion.VS2013.ToString())
                ?? new ConfigModel()
                {
                    ConfigValue = string.Empty
                };
            this.TxtVS2005.Text = configVS2005.ConfigValue;
            this.TxtVS2008.Text = configVS2008.ConfigValue;
            this.TxtVS2010.Text = configVS2010.ConfigValue;
            this.TxtVS2012.Text = configVS2012.ConfigValue;
            this.TxtVS2013.Text = configVS2013.ConfigValue;


            ConfigModel configPackTool = ConfigManager.GetConfig("PackTool")
                ?? new ConfigModel()
                {
                    ConfigValue = string.Empty
                };
            this.TxtPackTool.Text = configPackTool.ConfigValue;

            ConfigModel configHotkey = ConfigManager.GetConfig("Hotkey")
                ?? new ConfigModel()
                {
                    ConfigValue = string.Empty
                };
            this.TxtHotKey.Text = configHotkey.ConfigValue;
        }
        
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                ConfigManager.SaveConfig(new ConfigModel()
                {
                    ConfigName = VSVersion.VS2005.ToString(),
                    ConfigValue = TxtVS2005.Text
                });
                ConfigManager.SaveConfig(new ConfigModel()
                {
                    ConfigName = VSVersion.VS2008.ToString(),
                    ConfigValue = TxtVS2008.Text
                });
                ConfigManager.SaveConfig(new ConfigModel()
                {
                    ConfigName = VSVersion.VS2010.ToString(),
                    ConfigValue = TxtVS2010.Text
                });
                ConfigManager.SaveConfig(new ConfigModel()
                {
                    ConfigName = VSVersion.VS2012.ToString(),
                    ConfigValue = TxtVS2012.Text
                });
                ConfigManager.SaveConfig(new ConfigModel()
                {
                    ConfigName = VSVersion.VS2013.ToString(),
                    ConfigValue = TxtVS2013.Text
                });
                ConfigManager.SaveConfig(new ConfigModel()
                {
                    ConfigName = "PackTool",
                    ConfigValue = TxtPackTool.Text
                });
                ConfigManager.SaveConfig(new ConfigModel()
                {
                    ConfigName = "Hotkey",
                    ConfigValue = TxtHotKey.Text
                });
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示信息", MessageBoxButtons.OK);
            }
        }

        private void btnSelectVS2005_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.TxtVS2005.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void btnSelectVS2008_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.TxtVS2008.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void btnSelectVS2010_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.TxtVS2010.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void btnSelectVS2012_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.TxtVS2012.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void btnSelectVS2013_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.TxtVS2013.Text = folderBrowserDialog1.SelectedPath;
            }
        }
    }
}
